<?php
//include($_SERVER['DOCUMENT_ROOT'] . "/admin/includes/head.php");
include($_SERVER['DOCUMENT_ROOT'] . "/admin/includes/Interceptor.php");
include($_SERVER['DOCUMENT_ROOT'] . '/static/db/connect.php');

@$type = $_GET["type"];
if (isset($type) && $type != "") {
    $data_type = $type;
    switch ($type) {
        case "be":
            $data_type = "be";
            break;
        case "fe":
            $data_type = "fe";
            break;
    }
    ?>

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>layui</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link href="/static/css/resume/bootstrap.min.css" rel="stylesheet" type="text/css">
        <link rel="stylesheet" href="/admin/static/layui/css/layui.css" media="all">
    </head>
    <body>

    <form class="layui-form layui-form-pane" action="" method="post">
        <input type="hidden" name="type" value="<?php echo $type ?>">
        <div class="layui-form-item">
            <div class="layui-inline" style="width: 45%">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" required lay-verify="required" autocomplete="off"
                           placeholder="请输入标题"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <select name="sort">
                        <option value="0">0</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">概要</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="outline"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <!--                <textarea class="layui-textarea layui-hide" name="content" lay-verify="content"-->
                <!--                          id="LAY_editor"></textarea>-->
                <div id="editor"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="addData">立即提交</button>
            </div>
        </div>
    </form>

    <script type="text/javascript" src="https://unpkg.com/wangeditor/release/wangEditor.min.js"></script>
    <script type="text/javascript">
        var E = window.wangEditor
        var editor = new E('#editor')
        // 或者 var editor = new E( document.getElementById('#editor') )
        editor.create()
    </script>
    <script src="/admin/static/layui/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form', 'layedit'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , $ = layui.jquery;

            //监听提交
            form.on('submit(addData)', function (data) {
                console.log(editor.txt.html());
                var params = data.field;
                params.content = editor.txt.html();
                $.post("/admin/view/skill/addData.php", data.field, function (res) {
                    if (res == 1) {
                        layer.msg("新增成功！");
                        setTimeout(function () {
                            parent.closeModal();
                        }, 1000);
                    }
                });
                return false;
            });
        });
    </script>
    </body>
    </html>

    <?php
} else {
    @$type = $_POST["type"];
    if (isset($type) && $type != "") {
        $sort = $_POST["sort"];
        $title = $_POST["title"];
        $outline = $_POST["outline"];
        $content = $_POST["content"];
        $table_name = "";
        switch ($type) {
            case "be":
                $table_name = "qt_skill_be";
                break;
            case "fe":
                $table_name = "qt_skill_fe";
                break;
        }
        $sql = "insert into $table_name (sort, title, outline, content, date) VALUES ($sort, '$title', '$outline', '$content', now())";
        $mysqli->query($sql);
        echo 1;
    } else {
        echo 0;
    }
}

//$sql = "select count(*) c from qt_page_view";
//$mysqli_result = $mysqli->query($sql);
//$total_pv = $mysqli_result->fetch_assoc()['c'];
//
//$sql = "select count(*) c from qt_page_view where DATE_FORMAT(date,\"%Y,%m,%d\") = DATE_FORMAT(now(),\"%Y,%m,%d\")";
//$mysqli_result = $mysqli->query($sql);
//$today_pv = $mysqli_result->fetch_assoc()['c'];
$mysqli->close();

?>
